{% include "../common/header.html" %}
<style>
.breadcrumb{padding: 0 15px;}
.wangEditor-menu-shadow { z-index: 9999;}
.form-label{text-align:right}
.form-horizontal .form-label {
    text-align: right;
}
.dataTables_wrapper{
  padding: 10px 60px;
  float: left;
  min-height: 300px;
  /*border-bottom: 1px solid #ccc;*/
}
.submit_region{width: 100%;margin: 0 auto;text-align: center;margin: 10px;}
</style>
<div class="cl pd-5 bg-1 bk-gray mt-20" id="perlist" style="margin-bottom: 15px;overflow-y: scroll;">
    <input type="hidden" id="rid" value="{{rid}}"> {% for item in itemList%}
    <div class="dataTables_wrapper no-footer main">
        <h4>{{item.name}}</h4>
        <ul>
            {% for el in (item.perlist)%}
            <li>
                <span><input type="checkbox" class="percheck"name="name" value="{{el.permission}}" pid='{{el.id}}' {%if newArr.indexOf(el.id)>=0 %}checked{%endif%}></span>
                <span>{{el.pername}}</span>
                <input type="hidden" class="pids" value="">
                <input type="hidden" class="permissions" value="">
            </li>
            {%endfor%}
        </ul>
    </div>
    {%endfor%}
    <div style="clear:both"></div>
    <div class="row cl submit_region">
        <div class="">
            <button class="btn btn-secondary radius" id="savepermission" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
            <button onClick="window.location.href='/role'" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
        </div>
    </div>
</div>

{% include "../common/footer.html" %}
<script>
var windowHeight = $(window).height();
$("#perlist").css({
    "height":windowHeight
});


$("#savepermission").on('click',function(){
      var prr=[],pids=[];
      $.each($('input[type="checkbox"]',$('.main')),function(i,item){
          if($(item).is(':checked')){
              prr.push($(this).val());
              pids.push($(this).attr('pid'))
          }
      })
      var newData={
          id:$("#rid").val(),
          pid:pids.join(","),
          permission:prr.join(","),

      }
      $.ajax({
          url:'/role/rolesave',
          data:newData,
          type:'POST',
          success:function(json){
              if(json.errno===0){
                  alert("保存成功！");
                  window.location.href="/role"
              }else{
                  alert(json.errmsg)
              }
          }
      })
})
</script>
